package com.bingfor.easycablelink.my;

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;

import com.bingfor.easycablelink.R;
import com.bingfor.easycablelink.base.BaseActivity;
import com.bingfor.easycablelink.databinding.ActivityInvoiceInformationBinding;
import com.bumptech.glide.Glide;

import java.util.ArrayList;

import me.iwf.photopicker.PhotoPicker;

/**
*发票信息
*@author LY
*@time 2017/5/18 16:45
* des:create file and achieve model
*/
public class InvoiceInformationActivity extends BaseActivity {

    ActivityInvoiceInformationBinding binding;
    boolean flag = false;//是否可以编辑

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityInvoiceInformationBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initToolbar();
    }

    @Override
    public void initViews() {
        binding.setStatus(flag);
        binding.ivImg1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                PhotoPicker.builder()
                        .setPhotoCount(1)
                        .setShowCamera(true)
                        .setShowGif(true)
                        .setPreviewEnabled(false)
                        .start(mContext,PhotoPicker.REQUEST_CODE);
            }
        });

    }

    @Override
    public void initToolbar() {
        Toolbar toolbar = $(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setTitle("发票信息");
        initViews();
    }

    @Override
    public void refresh() {

    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.menu_right_invioce_edit, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        switch (item.getItemId()) {
            case R.id.menu_post:
                flag = flag==true?false:true;
                binding.setStatus(flag);
                break;
        }
        return super.onOptionsItemSelected(item);
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        if (resultCode == RESULT_OK && requestCode == PhotoPicker.REQUEST_CODE) {
            if (data != null) {
                ArrayList<String> photos =
                        data.getStringArrayListExtra(PhotoPicker.KEY_SELECTED_PHOTOS);
                Glide.with(mContext).load(photos.get(0)).into(binding.ivImg1);
            }
        }
    }
}
